<!--
 * @Date: 2022-04-15 15:00:44
 * @LastEditors: wuyuxin
 * @LastEditTime: 2022-04-16 11:39:47
 * @FilePath: \Vue3-ts-cms\src\views\login\components\login-panel.vue
 * @description: 文件描述
-->
<template>
  <div class="login-panel">
    <h1 class="title">后台管理系统</h1>
    <el-tabs type="border-card" class="demo-tabs" v-model="activeName" stretch>
      <el-tab-pane name="account">
        <template #label>
          <span> <user-filled class="icon-size" />账号登录 </span>
        </template>
        <login-account ref="accountRef" />
      </el-tab-pane>
      <el-tab-pane name="phone">
        <template #label>
          <span> <iphone class="icon-size" />手机登录 </span>
        </template>
        <login-phone ref="phoneRef" />
      </el-tab-pane>
    </el-tabs>
    <div class="account-control">
      <el-checkbox v-model="isKeepPassword">记住密码</el-checkbox>
      <el-link type="primary">忘记密码</el-link>
    </div>

    <el-button type="primary" class="login-btn" @click="LoginClick"
      >立即登录</el-button
    >
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue'
import LoginAccount from './login-account.vue'
import LoginPhone from './login-phone.vue'
import localCache from '@/utils/cache'

export default defineComponent({
  components: { LoginAccount, LoginPhone },
  setup() {
    const activeName = ref('account')
    const accountRef = ref<InstanceType<typeof LoginAccount>>()
    const phoneRef = ref<InstanceType<typeof LoginPhone>>()
    const isKeepPassword = ref(localCache.getCache('isKeepPassword') ?? false)
    const LoginClick = () => {
      if (activeName.value === 'account') {
        accountRef.value?.loginAction(isKeepPassword.value)
      } else {
        phoneRef.value?.loginAction()
      }
    }
    return {
      activeName,
      accountRef,
      phoneRef,
      LoginClick,
      isKeepPassword
    }
  }
})
</script>

<style scoped lang="less">
.login-panel {
  .icon-size {
    width: 12px;
    height: 12px;
    margin-right: 8px;
  }
  .title {
    text-align: center;
  }

  .account-control {
    margin-top: 10px;
    display: flex;
    justify-content: space-between;
  }

  .login-btn {
    width: 100%;
    margin-top: 10px;
  }
}
</style>
